package com.hnxxxy.sysmgr.mapper;


import com.hnxxxy.common.redis.RedisMyabtisCstCache;
import com.hnxxxy.entity.MenuExample;
import java.util.List;

import com.hnxxxy.sysmgr.pojo.Menu;
import com.hnxxxy.sysmgr.vo.MenuVo;
import com.hnxxxy.sysmgr.vo.StaffVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Repository
@CacheNamespace(implementation = RedisMyabtisCstCache.class)
public interface MenuMapper {
    /**
     * 查询菜单
     * @param menuVo
     * @return
     */
    @Select({"<script>",
            "select * from sys_menu ",
            "<where> ",
            "<if test='menuname!=null'>",
                "and menuname like concat('%',#{menuname},'%')",
            "</if>",
            "<if test='type!=null'>",
            "and type like concat(#{type})",
            "</if>",
            "</where>",
            "</script>"})
    List<Menu> queryAllMenu(MenuVo menuVo);

    /**
     * 添加菜单
     * @param menuVo
     */
    @Insert({"insert into sys_menu (menuname, url, icon, parentid, type) values (#{menuname},#{url},#{icon},#{parentid},#{type})"})
    void insertMenu(MenuVo menuVo);

    /**
     * 删除菜单
     * @param id
     */
    @Delete({"delete from sys_menu where id = #{id}"})
    void deleteMenu(Integer id);

    /**
     * 更新菜单
     * @param menuVo
     * @return
     */
    @Update({"<script>",
            "update sys_menu",
            "<set>",
            "<if test='menuname!=null'>",
            " menuname = #{menuname},",
            "</if>",
            "<if test='url!=null'>",
            "url=#{url},",
            "</if>",
            "<if test='icon!=null'>",
            " icon=#{icon},",
            "</if>",
            "<if test='parentid!=null'>",
            "parentid=#{parentid},",
            "</if>",
            "<if test='type!=null'>",
            "type=#{type},",
            "</if>",
            "</set>",
            "where id=#{id}",
            "</script>"})
    int updateMenu(MenuVo menuVo);



    /**
     * 根据pid查询菜单数量
     * @param pid
     * @return
     */
    @Select({"select count(1) from sys_menu where parentid=#{pid}"})
    Integer queryMenuByPid(Integer pid);

}